AArch32: Fix SCTLR context initialization
authorSoby Mathew <[email protected]>
Wed, 31 Aug 2016 11:34:33 +0000 (12:34 +0100)
committerSoby Mathew <[email protected]>
Wed, 31 Aug 2016 17:14:07 +0000 (18:14 +0100)
This patch fixes a bug in context management library when writing
SCTLR register during context initialization. The write happened
prior to initialization of the register context pointer. This
resulted in the compiler optimizing the write sequence from the
final binary and hence SCTLR remains uninitialized when
entering normal world. The bug is fixed by doing the
initialization of the register context pointer earlier in the
sequence.

Change-Id: Ic7465593a74534046b79f40446ffa1165c52ed76

lib/el3_runtime/aarch32/context_mgmt.c

index 6915ded7a32063b6ae2fe6a4b6d56cfe51091f35..bc5f9c429abd5d7dfefd27000a4b8f0181c14411 100644 (file)
@@ -86,6 +86,8 @@ static void cm_init_context_common(cpu_context_t *ctx, const entry_point_info_t
        /* Clear any residual register values from the context */
        memset(ctx, 0, sizeof(*ctx));
 
+       reg_ctx = get_regs_ctx(ctx);
+
        /*
         * Base the context SCR on the current value, adjust for entry point
         * specific requirements
@@ -121,8 +123,6 @@ static void cm_init_context_common(cpu_context_t *ctx, const entry_point_info_t
        if (GET_M32(ep->spsr) == MODE32_hyp)
                scr |= SCR_HCE_BIT;
 
-       reg_ctx = get_regs_ctx(ctx);
-
        write_ctx_reg(reg_ctx, CTX_SCR, scr);
        write_ctx_reg(reg_ctx, CTX_LR, ep->pc);
        write_ctx_reg(reg_ctx, CTX_SPSR, ep->spsr);